package musicstore.action;

import musicstore.biz.ShoppingCartBiz;
import musicstore.entity.ShoppingCart;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShoppingCartAction extends ActionSupport {
	private int albumId;
	public int getAlbumId() {
		return albumId;
	}
	public void setAlbumId(int albumId) {
		this.albumId = albumId;
	}


	private ShoppingCart getCart(){
		ShoppingCart cart = (ShoppingCart) ActionContext.getContext().getSession().get("cart");
		if(cart == null){
			cart = new ShoppingCart();
			ActionContext.getContext().getSession().put("cart", cart);
		}
		return cart;
	}

	private ShoppingCartBiz shoppingCartBiz;
	public void setShoppingCartBiz(ShoppingCartBiz shoppingCartBiz) {
		this.shoppingCartBiz = shoppingCartBiz;
	}
	
	public String add(){
		shoppingCartBiz.addItemToCart(this.getCart(), albumId);
		return SUCCESS;
	}
	
	public String remove(){
		shoppingCartBiz.removeItemToCart(this.getCart(), albumId);
		return SUCCESS;
	}
}
